# encoding:utf-8
# 读取ini配置文件
import os
import configparser
from config.all_paths import get_root_path

class LoadIni:

    def __init__(self, confName='test_config.ini'):
        TEST_CONFIG = os.path.join(get_root_path(), "config", confName)
        # print(TEST_CONFIG)
        self.conf = configparser.RawConfigParser()
        self.conf.read(TEST_CONFIG, encoding='utf-8')

    # 获取单个key对应的value
    def getConfig(self, section, option):
        return self.conf.get(section, option)
    #获取所有的配置,返回一个{}
    def getAllConfig(self):
        g_config = {}
        section = self.conf.sections()
        for config_name in section:
            for item in self.conf.items(config_name):
                g_config[item[0]] = item[1]
        # print("读取的配置项",g_config)
        return g_config
    #获取一个section内所有的值
    def getSection(self,section):
        g_config = {}
        g_list = self.conf.items(section)
        for i in g_list:
            g_config[i[0]] = i[1]
        return g_config





if __name__ == '__main__':
    # print(LoadIni().getConfig('test_caihong', 'host'))
    # print(LoadIni('pro_config.ini').getAllConfig())
    print(LoadIni('pro_wutong.ini').getSection('cd-yzzg'))
